package Offer.offer2017;

/**
 * 把数组排成最小的数
 * Created by 雷文康 on 2018/1/3.
 */
public class Test33 {
    public static void main(String[] args) {
        int[] array = {3, 32, 321};
        printMin(array);
    }

    public static void printMin(int[] array){
        if (array == null || array.length == 0){
            return;
        }
        for (int i = 0; i < array.length; i++) {
            for (int j = array.length - 1; j > i ; j--) {
                if (compare(array[j],array[j - 1]) < 0){
                     int temp = array[j];
                     array[j] = array[j - 1];
                     array[j - 1] = temp;
                }
            }
        }

        for (int i = 0; i < array.length; i++) {
            System.out.print(array[i]);
        }

    }

    public static int compare(int m, int n){
        String a = m + "" + n;
        String b = n + "" + m;
        return a.compareTo(b);
    }
}
